<?php
/**
 * @file
 * Connects to a MySQL database.
 *
 * Usage:
 *  - A page that wants to connect to a MySQL database should include/require
 *    this page once (and only once).
 *  - Use 'db_mysql_disconnect.php' to disconnect from the MySQL database.
 *
 * Parameter(s):
 *  - $DB_HOST     : MySQL database host.
 *  - $DB_USER     : MySQL database user ID.
 *  - $DB_PASS     : MySQL database user password.
 *  - $DB_NAME     : MySQL database name.
 *  - $DB_ENCODING : MySQL database encoding.
 *
 * Global variable(s) set:
 *  - $db_mysql_connection : MySQL database connection.
 *
 * Global variable(s) unset:
 *  - None.
 *
 * Exception(s):
 *  - Throws an 'Exception' object if connection to MySQL database fails.
 *
 * This file includes/requires:
 *  - None.
 */

// global variable(s) ==========================================================
$db_mysql_connection = null;  //!< MySQL database connection.


// implementation ==============================================================
// connect to mysql database server
$db_mysql_connection = mysql_connect($DB_HOST, $DB_USER, $DB_PASS);
if (false == $db_mysql_connection) {
  // failed to connect to mysql database server
  throw new Exception(mysql_error());
}
// select database
if (false == mysql_select_db($DB_NAME, $db_mysql_connection)) {
  // failed to select database
  throw new Exception(mysql_error());
}
// set encoding
if (false == mysql_query("set names '" . $DB_ENCODING . "'")) {
  // failed to set encoding
  // do nothing
}
?>
